# Maintainer(Arch): Felix Yan <felixonmars@archlinux.org>
# Maintainer: Sagar Acharya <sagaracharya@tutanota.com>

pkgname=abc
pkgver=0.0.0.20191006
_commit=52a8ebb451b060673e68319c43a0e499700c7212
pkgrel=1
pkgdesc="System for Sequential Logic Synthesis and Formal Verification"
arch=("x86_64")
license=("Expat")
url="https://github.com/berkeley-abc/abc"
depends=('readline')
source=("https://github.com/berkeley-abc/abc/archive/$_commit/abc-$_commit.tar.gz"
		"series"
		"0006-Fix-spelling-errors.patch"
		"cflags_ldflags.patch"
		"remove_bzlib_convenience.patch"
		"remove_zlib_convenience.patch"
		"reproducibility.patch"
		"writepla.patch")
sha512sums=('d8005c66e1682aed1e371ab927ff23ce2d92d286b22d2c06bf1c78b8250850183df269f3d5949fb36fa7e142c2377c7e2065eeefbc0754f7ee7ba17b8e300ec1'
			'9eb3c9b4a578871c18d386f14937557842b5be8f9a864042a8b4948fd9806d519b948da5c42715fe8c1c607c002db7e2683a21805403a125edfb8a8f85d207e9'
			'2a42c11916aaf7c479bae9904878392059a1bd0aeff436c06e1b6ad82f15afaeda039625729ce695aadb53c5a3cd94b26ff8321d62245f327d8d48a5d6e3baca'
			'11d0b68a5f2ca1830667f1a0b4f7fb3c61035af47a1b42e805f61c4c36d649bbed62df0cb815d28cc3197eb768bbf57213f33596681beba16f8d58c7fe656b25'
			'a505df37df8ee0acb80deacf03699a010e7d73201f1250a893e46c8e59ba0ec514490eadac2bad630a20dbcc7e6844bf124d9425a6c26330dead3cbebfebe95e'
			'a2e744058f5916b6a33e581ff1a7dbbccfa8341c63a209107da7891b95a7a37da5e30966dc97c09281f1b4a5c0d8a4707c6653cbba10cdf36c59615fec8b240c'
			'8ff28afb4daa77a11ef6e428cab1f25e38e25bf60d2d95640ee87dbb4cf8127817570cce7d118dca6f306b06a5c3b0bcfb53b396155d8e6eb4f5bec5cb8ab8ea'
			'2f246f65d6ce9e58f0d98e4756634dd398e490e60794e85c796c0eec5364cde89acec7964a99902009a7c397abb84362ff5377f932f5d5d1961afdb02e6b8aa8')

prepare() {
  cd $pkgname-$_commit

  mkdir ./patches
  cp ${srcdir}/series ./patches
  cp ${srcdir}/*.patch ./patches

  export QUILT_PATCHES=patches
  export QUILT_REFRESH_ARGS='-p ab --no-timestamps --no-index'
  export QUILT_DIFF_ARGS='--no-timestamps'

  quilt push -av

  # - Make abc link to libabc, so the result is 50% smaller
  # - Fix LDFLAGS for shared library
  sed -i -e 's|-o \$@ \$\^ \$(LDFLAGS)|-o $@ src/base/main/main.o $(LDFLAGS) -L. -labc|;s|\$(PROG):|$(PROG): lib$(PROG).so|' \
         -e 's|-o \$@ \$\^ $(LIBS)|-o $@ $^ $(LIBS) $(LDFLAGS)|' Makefile
}

build() {
  cd $pkgname-$_commit
  make ABC_USE_PIC=1 LDFLAGS="$LDFLAGS" libabc.so abc
}

package() {
  cd $pkgname-$_commit
  install -Dm755 libabc.so -t "$pkgdir"/usr/lib/
  install -Dm755 abc -t "$pkgdir"/usr/bin/
  install -Dm644 copyright.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}
